<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
    	<meta name="viewport" content="width=device-width, initial-scale=1.0">
    	<meta http-equiv="X-UA-Compatible" content="IE=edge,Chrome=1" />
		<title>修改密码</title>
		<script type="text/javascript" src="js/common.js"></script>
	</head>
	<body>
		<div id="frame_child">
			<div class="accounttitle">
				<p>账号>修改密码</p>
            </div>

			<form class="form-horizontal" role="form" style="width: 500px;margin: 50px auto;">
                <div class="form-group">
                  <label for="oldpass" class="col-sm-2 control-label">旧密码</label>
                  <div class="col-sm-10">
                    <input type="password" class="form-control" id="oldpass" placeholder="请输入旧密码">
                  </div>
                </div>
                <div class="form-group">
                    <label for="newpass" class="col-sm-2 control-label">新密码</label>
                    <div class="col-sm-10">
                      <input type="password" class="form-control" id="newpass" placeholder="请输入新密码">
                    </div>
                </div>
                <div class="form-group">
                  <div class="col-sm-offset-2 col-sm-10">
                    <button type="button" class="btn btn-primary edit-password">修改密码</button>
                  </div>
                </div>
            </form>
        </div>

        
        <script type="text/javascript">
			
            $(document).ready(function(){
                $('.edit-password').click(function(){
                    var oldpass = $('#oldpass').val()
                    var newpass = $('#newpass').val()
                    if (oldpass == '' || newpass == '') {
                        showErr("新旧密码不能为空")
                    } else if (oldpass === newpass) {
                        showErr("新旧密码不能相同")
                    } else {
                        $.ajax({
                        url: service_url + '/a/zkUser/modifyPwd?oldPassword='+encodeURIComponent(oldpass)+'&newPassword='+encodeURIComponent(newpass)+'&token=' + $.cookie('AuthorizationAdmin'),
                        type: 'POST',
                        xhrFields: {
                            withCredentials: true
                        },
                        crossDomain: true,
                        contentType: 'application/json',
                        dataType: 'jsonp',
                        jsonpCallback:"success_jsonpCallback",  
                        processData: false, // 告诉jQuery不要去处理发送的数据
                        success: function(data) {
                            console.log(data)
                            if (data.status === '00') {
                                top.alert("密码修改成功",'', function() {
                                    window.parent.location.href = "login.html";
                                },{type: 'success'});
                            } else {
                                showErr(data.msg || '修改密码失败')
                            } 
                        },
                        error: function(XMLHttpRequest, textStatus, errorThrown) {
                            console.log(XMLHttpRequest, textStatus, errorThrown)
                        }
                    })
                    }
                    // top.alert("删除成功",{type: 'success'});
                })
            })


        </script>
	</body>

</html>